
def max_sub(N,raw):
    max_sum =This_sum = 0
    for i in range(0,N):
        This_sum += raw[i]
        if This_sum > max_sum:
            max_sum =This_sum
        elif This_sum<0:
            This_sum = 0
    return max_sum

def max_sub2(N,raw):
    max_sum = 0
    for i in range(0,N):
        This_sum  = 0
        for j in range(i,N):
            This_sum += raw[j]
            if This_sum > max_sum :
                max_sum = This_sum
    return max_sum

if __name__ == '__main__':
    N = int(input())
    raw = []
    raw = [int(n) for n in input().split()]
    print(max_sub2(N,raw))